#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>

typedef int HPDateType;

typedef struct Heap
{
	HPDateType* a;
	int size;
	int capacity;

}Heap;

void AdjustUp(HPDateType* a, int child)
{
	int parent = (child - 1) / 2;
	while (child > 0)
	{
		if (a[child] < a[parent])
		{
			swap(&a[child], &a[parent]);
			child = parent;
			parent = (child - 1) / 2;
		}
		else
		{
			break;
		}
	}
}


void AdjustDown(int* a, int n)
{
	int parent = 0;
	int child = parent * 2 + 1;
	while (child < n)
	{
		if (a[child] < a[child + 1] && child + 1 < n)
		{
			child++;
		}

		if (a[child] > a[parent])
		{
			swap(&a[child], &a[parent]);
			parent = child;
			child = parent * 2 + 1;
		}
		else
		{
			break;
		}
	}
}

void swap(int* p1, int* p2)
{
	int tmp = *p1;
	*p1 = *p2;
	*p2 = tmp;
}


void HeapSort(int* a, int n)
{
	for (int i = 0; i < n; i++)
	{
		AdjustUp(a, i);
	}

	int end = n - 1;
	while (end--)
	{
		swap(&a[0], &a[end]);
		AdjustDown(a, end);
	}
}

int main()
{
	int a[] = { 20,17,4,16,5,3 };

	return 0;
}